package examination;

import java.util.Scanner;

/**
 * @author Xiao
 * @date 2021/7/10
 */
@SuppressWarnings("all")
public class Test01 {
    /**
     *      统计字符串中各类字符数量：
     *          从键盘录入一个字符串，要求该字符串必须含有大写字母，否则提示重新输入。
     *          统计并打印字符串中大写字母、小写字母、数字字符、其他字符的个数。
     */
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int countA_Z = 0;
        int counta_z = 0;
        int count0_9 = 0;
        int countOthers = 0;
        System.out.println("请输入一个字符串：");
        while (true) {
            String s = sc.nextLine();
            for (int i = 0; i < s.length(); i++) {
                char ch = s.charAt(i);
                if (ch >= 'A' && ch <= 'Z') {
                    countA_Z++;
                }
            }
            if (countA_Z == 0) {
                System.out.println("您输入的字符串中没有大写字母。请重新输入：");
                continue;
            } else {
                for (int i = 0; i < s.length(); i++) {
                    char ch = s.charAt(i);
                    if (ch < 'A' || ch > 'Z') {
                        if (ch >= 'a' && ch <= 'z') {
                            counta_z++;
                        } else if (ch >= '0' && ch <= '9') {
                            count0_9++;
                        } else {
                            countOthers++;
                        }
                    }
                }
                break;
            }
        }
        System.out.println("------------------");
        System.out.println("countA_Z：" + countA_Z);
        System.out.println("counta_z：" + counta_z);
        System.out.println("count0_9：" + count0_9);
        System.out.println("countOthers：" + countOthers);
    }
}
